﻿using Framework.Core.Reflection;

namespace Framework.Core.Recorder
{
    internal class PropertyCallKeyBuilder : ICallKeyBuilder
    {
        private readonly ICallKeyBuilder callKeyBuilder;
        private readonly ICallKeyBuilder propertyCallKeyBuilder;

        public PropertyCallKeyBuilder(ICallKeyBuilder callKeyBuilder)
        {
            this.callKeyBuilder = callKeyBuilder;
            propertyCallKeyBuilder = new StateFullCallKeyBuilder(callKeyBuilder);
        }

        public string Build(IMethod method)
        {
            return IsProperty(method) ? propertyCallKeyBuilder.Build(method) : callKeyBuilder.Build(method);
        }

        private static bool IsProperty(IMethod method)
        {
            var methodName = method.Name;
            return methodName.Contains("get_") || methodName.Contains("set_");
        }
    }
}